package modelo;

import hbt.AbstractHibernateManager;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import entities.CartaEntity;
import entities.SucursalEntity;

public class CartaDao extends AbstractHibernateManager{

	private static CartaDao instancia = null;
	
	public static CartaDao getInstancia() {
		if(instancia == null) {
			instancia = new CartaDao();
		}
		return instancia;
	}
		public void save (CartaEntity fact){
			Session s = null;
			try {
				s=getNewSession();
				s.beginTransaction();
				s.persist(fact);
				s.flush();
				s.getTransaction().commit();
				System.out.println("[Carta SAVED ON TABLE cartas y Itemscartas]::OK");
			} catch (HibernateException e) {
				e.printStackTrace();
			} finally{
				closeSession(s);
			}
		}
		
		public CartaEntity obtenerCarta(Integer idCarta) {
			Session s = null;
			CartaEntity carta = new CartaEntity();
			
			try {
				s = getNewSession();
				carta =  (CartaEntity) s.createQuery("FROM CartaEntity carta " +
										"WHERE carta.id = :idCarta")
								  .setInteger("idCarta", idCarta)
								  .uniqueResult();
				
			} catch (HibernateException e) {
				e.printStackTrace();
			} finally{
				closeSession(s);
			}
			return carta;
		}


}
